using System;
using Tools.Domain.Specifications.Common;
using Tools.Domain.Specifications.Common.Reflection;
using Tools.Domain.Specifications.Constraints;
using Webshop20.Domain.Security.Authentication.Core;

namespace Webshop20.Domain.Security.Authentication.Core
{
    [Serializable]
    public class AccountConstraintSet : ConstraintSetBase<Account>
    {
        private const int PASSWORD_MINIUM_LENGTH = 6;

        public AccountConstraintSet(IConstraintContext constraintContext)
            : base(constraintContext)
        {
            ForMethod(account => account.SetAccountData(null, null, null, null, null, null, null))
                .AddPrecondition(new StringFieldIsNotNullOrEmpty<SetAccountDataDTO>(x => x.PasswordConfirm, "PASSWORD_CONFIRM_EMPTY"))
                .AddPrecondition( new EqualAs<SetAccountDataDTO>(x=>x.Password, y=>y.PasswordConfirm))
                .AddInvariant(new StringFieldIsNotNullOrEmpty<Account>(x => x.Password, "PASSWORD_EMPTY"))
                .AddInvariant(new StringFieldIsNotNullOrEmpty<Account>(x=>x.LoginName, "LOGIN_NAME_EMPTY"))
                .AddInvariant(new StringFieldValueHasMinimumLength<Account>(x => x.Password, "PASSWORD_TOO_SHORT",
                                                                            PASSWORD_MINIUM_LENGTH));
        }

    }
}